#include "main/utils.h"
#include "lib/binary_tree.h"
using namespace std;

void convertBinaryTree(BinaryTreeNode* root) {
  stack<BinaryTreeNode*> help_stack;
  BinaryTreeNode* cur_node = root;
  int sum = 0;
  while (cur_node || !help_stack.empty()) {
    while (cur_node) {
      help_stack.push(cur_node);
      cur_node = cur_node->right;
    }
    cur_node = help_stack.top();
    help_stack.pop();
    sum += cur_node->value;
    cur_node->value = sum;
    cur_node = cur_node->left;
  }
}

int main() {
  vector<int> vec = {4, 2, 6, 1, 3, 5, 7};
  BinaryTreeNode* root = CreateBinaryTree(vec);
  PrintBinaryTree(root);
  convertBinaryTree(root);
  PrintBinaryTree(root);

  return 0;
}
